package com.wtoip;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer;
import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer;
import org.springframework.boot.context.web.SpringBootServletInitializer;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.ImportResource;

import com.wtoip.domain.UserVO;
import com.wtoip.service.UserService;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

@ComponentScan
@EnableAutoConfiguration
@ImportResource("classpath:dubbo-provider.xml")
public class Application extends SpringBootServletInitializer implements EmbeddedServletContainerCustomizer {
	
	/**
	 * 程序主入口
	 * @param args
	 * @throws Exception
	 */
	public static void main(String[] args) throws Exception {
		ConfigurableApplicationContext context = SpringApplication.run(Application.class, args);
		System.err.println("============================ Dubbo服务启动成功 ============================");
		
		UserService userService = context.getBean(UserService.class);
		
		UserVO userVO = userService.getUserById(1);
		System.out.println(userVO);
		
		JedisPool jedisPool = context.getBean(JedisPool.class);
		Jedis jedis = jedisPool.getResource();
		
		jedis.set("daxiong", "1");
		String data = jedis.get("daxiong");
		
		System.out.println(data);
	}
	
	//自定义端口号
	@Override
	public void customize(ConfigurableEmbeddedServletContainer container) {
		container.setPort(8181);
	}
	
	@Override  
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {  
        return builder.sources(Application.class);  
    }
}
